/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cis36_gardengame;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 *
 * @author Jonah
 */
public class BoardGraphics extends JPanel {
    
    private BufferedImage rock;
    private BufferedImage bg;
    private BufferedImage scaledRock;
    private BufferedImage scaledBG;

    public BoardGraphics() {
    }
    private void loadResources() {
        //implement code
        bg = loadImage("src/cis36b/cis36/bgTile.png");
        rock = loadImage("src/cis36b/cis36/rock.png");
    }
    
    public void drawTile( Tile tile, BoardState bs, Graphics g) {
        int xPos = (tile.getIndex() % bs.getColumns()) * bs.getPixels();
        int yPos = (tile.getIndex() / bs.getRows()) * bs.getPixels();
        
        g.drawImage(scaledBG, xPos, yPos, this);
    }
    
    public void displayGameState( GameState gameState ) {
        //implement code
    }
    
        public static BufferedImage loadImage(String ref) {  
        BufferedImage bimg = null;  
        try {  
  
            bimg = ImageIO.read(new File(ref));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return bimg;  
    } 
    
    public static BufferedImage resize(BufferedImage img, int newW, int newH) {  
        int w = img.getWidth();  
        int h = img.getHeight();  
        BufferedImage dimg = dimg = new BufferedImage(newW, newH, img.getType());  
        Graphics2D g = dimg.createGraphics();  
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
        g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);  
        g.dispose();  
        return dimg;  
    }  
}
